/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package serverbalancing;

import Server.ChatServer;
import java.util.ArrayList;

/**
 *
 * @author Thanhpv
 */
public class ServerBalancing {
  private static ServerBalancing serverBalancing;
  private final ArrayList<ChatServer> chatServerList; 
  public static ServerBalancing createInstance(){
     if(serverBalancing==null) {
         serverBalancing = new ServerBalancing();
     }
     return serverBalancing;
  }
  private ServerBalancing(){
      chatServerList = new ArrayList();
  }
  public ChatServer getChatServer(int count){
      int tmp = count%chatServerList.size()==0?chatServerList.size()-1:count%chatServerList.size()-1;
      chatServerList.set(tmp, new ChatServer(chatServerList.get(tmp).getHost(), chatServerList.get(tmp).getPort(), chatServerList.get(tmp).getNumUser()+1));
      ChatServer chatServer = chatServerList.get(tmp);
      System.out.println("inner ServerBalancing: " + chatServer.getNumUser());
      return chatServer;
  }
  public void addChatServer(String hostName, int port){
      chatServerList.add(new ChatServer(hostName, port));
  }
  public void userOfEachServer(){
      for(int i=0; i<chatServerList.size(); i++){
      }
  }
}
